var idproposta	= null;
var request		= new XMLHttpRequest();

window.onload = function () {
	idproposta = document.getElementById("idpropostaupdate").value;
	completaFormulario();
};

function completaFormulario(){
	request.open("POST", "../controller/BuscaPropostaById.php", true);
    //request.setRequestHeader("Content-type", "application/json");
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    request.onreadystatechange = function() {
	
		if(request.readyState == 4 && request.status == 200) {
			//location.reload()
			var proposta = JSON.parse(request.responseText);
			
			var cliente = document.getElementById("cliente");
			cliente.options[proposta.idcliente].selected = true;
			
			var obra = document.getElementById("obra");
			obra.value = proposta.obra;
		}
    }
    request.send("idproposta="+idproposta);	
}
